<template>
	<view class="container">
		<!-- 空白页 -->
		<empty v-if="emptyShow" :custom="true" src="../../../static/images/no-orders.png" text="无相关卡券"></empty>
		<!-- 旅游卡 -->
		<view class="tourismCard">
			<view class="rosa">
				<view class="tapBox">
					<view class="cardListTab">
						<text class="tit">旅游卡</text>
						<view class="recode">
							<text class="text" @tap="tourismCardRecord">旅游卡记录</text>
							<text class="yticon icon-you"></text>
						</view>
					</view>
				</view>
				<view class="card" v-for="(item,index) in TourismListA" :key="index">
					<view class="left">
						<view class="cardName">
							<text class="name">{{TourismListdata.waitConfig.title}}</text>
						</view>
						<text class="cardDesc">{{TourismListdata.waitConfig.sub_title}}</text>
					</view>
					<view class="right">
						<view class="btn" @tap="activationTourismCard(item)">激活</view>
					</view>
				</view>
				<view class="card" :class="index + 1 == TourismListB.length?'marginNone':''" v-for="(item,index) in TourismListB"
				 :key="item.id">
					<view class="left">
						<view class="cardName">
							<text class="name">{{TourismListdata.waitConfig.title}}</text>
						</view>
						<view class="a">
							<text class="c">{{item.card_number}}</text>
							<text class="d">{{item.realname}}</text>
						</view>
						<view class="b">
							<text class="c">有效期至</text>
							<text class="d">{{item.validtime_str}}</text>
						</view>
					</view>
					<view class="right">
						<view class="btn" @tap="useTourismCard(item)">使用</view>
					</view>
				</view>
			</view>


			<!-- 刺梨卡  -->
			<view class="rosa tratt" v-if="TrattListB || TrattListA">
				<view class="tapBox">
					<view class="cardListTab">
						<text class="tit">套餐卡</text>
						<view class="recode">
							<text class="text" @tap="goSetList">前往套餐卡专区</text>
							<text class="yticon icon-you"></text>
						</view>
					</view>
				</view>
				<!-- 未激活 -->
				<view class="card" v-for="(item,index) in TrattListB" :key="item.id">
					<view class="left">
						<view class="cardName">
							<text class="name">{{item.card_name}}</text>
						</view>
						<text class="cardDescs">输入卡号卡密即可激活</text>
					</view>
					<view class="right">
						<!-- item -->
						<view class="btn" @tap="activationTourismCard(item,1)">激活</view>
					</view>
				</view>
				<!-- 已激活 -->
				<view class="card" v-for="(item,index) in TrattListA" :key="item.id">
					<view class="left">
						<view class="a">
							<text class="c">{{item.card_name}}</text>
							<text class="d">{{item.type_name}}</text>
						</view>
						<view class="cardName">
							<text class="names">{{item.card_number}}</text>
						</view>
					</view>
					<view class="right">
						<view class="btn" @tap="useTourismCard(item,1)">立即使用</view>
					</view>
				</view>
			</view>

		</view>
	</view>
</template>

<script>
	import {
		travelGetCardList
	} from "@/api/user.js"
	import {
		trattCard
	} from "@/api/order.js"

	export default {
		data() {
			return {
				emptyShow: false,
				TourismListdata: {},
				TourismListA: [],
				TourismListB: [],
				TrattListA: [], //刺梨套餐已激活
				TrattListB: [], //刺梨套餐未激活
				order:false, //是否从订单页面过来
			};
		},
		onLoad(options) {
			if(options.tratt == 1){
				this.order = true
			}
			this.getTourismList()
			

		},
		methods: {
			// *************************旅游卡**********************
			tourismCardRecord() {
				uni.navigateTo({
					url: "/pages/center/vip/tourismCardRecorde?title=" + this.TourismListdata.k2Config.title
				})
			},
			async getTourismList() {
				let res1 = await trattCard()
				this.TrattListA = res1.data.aCiliList
				this.TrattListB = res1.data.wCiliList
				let res = await travelGetCardList()
				this.TourismListdata = res.data.travelConfig
				this.TourismListA = res.data.waitList
				this.TourismListB = res.data.activationList.map((val, key) => {
					val.validtime_str = val.validtime_str.slice(0, 10)
					return val
				})
				if (this.TourismListA.length == 0 && this.TourismListB.length == 0 && this.TrattList.length == 0 && this.TrattListB
					.length == 0) {
					this.emptyShow = true
				}
			},
			activationTourismCard(item, type) {
				let url = ''
				if (type) {
					if(this.order){
						url = "/pages/center/prickly/activation?item=" + encodeURIComponent(JSON.stringify(item))+'&type=1'
					}else{
						url = "/pages/center/prickly/activation?item=" + encodeURIComponent(JSON.stringify(item))+'&type='
					}
					
				} else {
					url ="/pages/center/vip/tourismCardAct?item=" + encodeURIComponent(JSON.stringify(item))
				}
				uni.$on('change',(res)=>{
					this.getTourismList()
				})
				uni.navigateTo({
					url
				})
			},
			useTourismCard(item, type) {
				let url = ''
				if (type) {
					url =  '/pages/center/prickly/setMeal' 
				} else {
					url ="/pages/center/vip/tourismLandmark"
					uni.setStorageSync("tourismCardNo", item.id)
				}
				uni.navigateTo({
					url
				})
			},

			// *************************刺梨卡**********************
			goSetList() {
				uni.navigateTo({
					url: "/pages/center/prickly/setMeal"
				})
			}
		}
	};
</script>
<style>
	page {
		background-color: #F6F6F6;
	}
</style>

<style lang="scss" scoped>
	.container {
		.tourismCard {
			padding-top: 30rpx;
			margin-bottom: 30rpx;
			border-radius: 30rpx;

			.tapBox {
				display: flex;
				height: 88rpx;
				z-index: 2;
				background-color: #fff;
				border-radius: 30rpx;

				.cardListTab {
					width: 100%;
					line-height: 88rpx;
					color: #666666;
					font-size: 36rpx;
					font-weight: bold;
					display: flex;
					// justify-content: center;
					align-items: center;
					position: relative;

					.cardIcon {
						width: 52rpx;
						height: 40rpx;
						margin-right: 20rpx;
					}

					.recode {
						position: absolute;
						top: 0;
						right: 0;
						font-size: 24rpx;
						color: #999;
						line-height: 88rpx;
						font-weight: normal;

						.yticon {
							margin-left: 4rpx;
							font-size: 22rpx;
						}
					}
				}
			}

			.card {
				margin-bottom: 30rpx;
				width: 690rpx;
				padding: 30rpx 40rpx;
				box-sizing: border-box;
				height: 200rpx;
				background: linear-gradient(90deg, #209CFF 0%, #68E0CF 100%);
				border-radius: 10rpx;
				display: flex;
				justify-content: space-between;
				align-items: center;
				position: relative;

				.label {
					position: absolute;
					left: 36rpx;
					top: 24rpx;
					border-radius: 4rpx;
					padding: 4rpx 10rpx;
					background: rgba(0, 0, 0, .15);
					font-size: 24rpx;
					font-weight: bold;
					color: #FFFFFF;
				}

				.left {
					display: flex;
					flex-direction: column;

					.cardName {
						.name {
							font-size: 42rpx;
							font-weight: bold;
							color: #fff;
						}
					}

					.cardDesc {
						margin-top: 16rpx;
						font-size: 30rpx;
						color: #fff;
					}

					.a {
						margin-top: 10rpx;
						display: flex;
						align-items: baseline;
						color: #fff;
						font-size: 30rpx;
						font-weight: bold;

						.d {
							margin-left: 18rpx;
						}
					}

					.b {
						display: flex;
						align-items: baseline;
						color: #fff;
						font-size: 24rpx;
						opacity: .7;
					}
				}

				.right {
					display: flex;
					flex-direction: column;
					justify-content: center;
					align-items: flex-end;

					.btn {
						width: 160rpx;
						height: 60rpx;
						background: #fff;
						border-radius: 30px;
						line-height: 60rpx;
						text-align: center;
						font-size: 28rpx;
						color: #2699F0;
					}
				}
			}

			.marginNone {
				margin: 0;
			}
		}

		.rosa {
			background-color: #FFFFFF;
			margin-bottom: 30rpx;
			border-radius: 30rpx;
			padding: 0 30rpx 10rpx;
			box-sizing: border-box;
		}

		.tratt {
			.card {
				background: linear-gradient(-90deg, #FACC22 0%, #FF5627 100%);

				.left {
					.a {
						vertical-align: baseline;
					}

					.c {
						font-size: 42rpx;
						font-weight: bold;
					}

					.d {
						font-size: 32rpx;
					}

					.names {
						font-size: 32rpx;
						color: #FFFFFF;
						line-height: 1;
						display: inline-block;
						margin-top: 15rpx;
					}

					.cardDescs {
						margin-top: 16rpx;
						color: #FECFBC;
						font-size: 32rpx;
					}
				}

				.right {
					.btn {
						background: #FBD14F;
						color: #FFFFFF;
						font-size: 32rpx;
						// font-weight: bold;

					}
				}

			}
		}
	}
</style>
